package com.youth.platform.jdbc;


import org.logicalcobwebs.proxool.ProxoolDataSource;

import com.youth.framework.core.SystemContext;
import com.youth.framework.util.Assert;

/**
 * 对标准JDBC接口 {@link javax.sql.DataSource} 的简单实现，该实现将从系统的环境变量中获取创建
 * 数据库连接所必须的参数信息。
 * 
 */
public class RemoteDataSource extends ProxoolDataSource {
	
	public RemoteDataSource(){
		String dcn = SystemContext.getProperty("datasource.driverClassName");
		String url = SystemContext.getProperty("datasource.url");
		String username = SystemContext.getProperty("datasource.username");
		String password = SystemContext.getProperty("datasource.password");
		password = com.youth.framework.util.AESEncrypter.getInstance().decrypt(password, com.youth.framework.util.AESEncrypter.AES_ENCRYPT_KEY);
		
		Assert.hasText(dcn, "System Enviroment 'datasource.driverClassName' are not setted，or it's value must not empty");
		Assert.hasText(url, "System Enviroment 'datasource.url' are not setted，or it's value must not empty");
		Assert.hasText(username, "System Enviroment 'datasource.username' are not setted，or it's value must not empty");
		Assert.hasText(password, "System Enviroment 'datasource.password' are not setted，or it's value must not empty");
		
		super.setDriver(dcn);
		super.setDriverUrl(url);
		super.setUser(username);
		super.setPassword(password);
	}
}
